package ControlLayer;

import DBLayer.DBSal;
import DBLayer.DbConnection1;
import ModelLayer.Sal;


public class SalCtr 
{
	
	public SalCtr()
	{
	}
	
	/**
	 * Creates a new Sal with
	 * @param salNr
	 * @param antalPladser
	 * @param is3D
	 */
	public void createSal(byte salNr, int antalPladser, boolean is3D) 
	{
		Sal salObj = new Sal();

		salObj.setSalNr(salNr);
		salObj.setAntalPladser(antalPladser);
		salObj.setIs3D(is3D);

		try 
		{
			DbConnection1.startTransaction();
			DBSal dbsal = new DBSal();
			dbsal.insertSal(salObj);
			DbConnection1.commitTransaction();
		} 
		catch (Exception e) 
		{
			DbConnection1.rollbackTransaction();
		}
	}
	/**
	 * Finds a Sal with
	 * @param salNr
	 * @return
	 */
	public Sal findSal(byte salNr) 
	{
		DBSal dbsal = new DBSal();
		Sal result = dbsal.getSal(salNr, false);
		return result;
	}
	/**Removes a Sal with
	 * 
	 * @param salnr
	 */
	public void removeSal(byte salnr) 
	{
		DBSal dbsal = new DBSal();
		dbsal.deleteSal(salnr);
	}
	/**updates a Sal with
	 * 
	 * @param salNr
	 * @param antalPladser
	 * @param is3D
	 * @return
	 */
	public int updateSal(byte salNr, int antalPladser, boolean is3D) 
	{
		DBSal dbsal = new DBSal();
		Sal salObj = findSal(salNr);
		salObj.setAntalPladser(antalPladser);
		salObj.setIs3D(is3D);
		return dbsal.updateSal(salObj);
		
	}
}

